package com.xhj.bigfactory.bigFactory.blockingQueue;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * -
 *
 * @author 周沫 @Date 2021-07-30 @Time 1:14
 */
public class BlockingQueueDemo {

  public static void main(String[] args) {
    BlockingQueue<String> blockingQueue = new ArrayBlockingQueue<>(3);
    //		System.out.println(blockingQueue.add("qwer"));
    //		System.out.println(blockingQueue.add("asdf"));
    //		System.out.println(blockingQueue.add("zxcv"));
    //
    //		String element = blockingQueue.element();
    //		System.out.println("element = " + element);
    //		System.out.println(blockingQueue.element());
    //		System.out.println(blockingQueue.element());
    //
    //		System.out.println("===============================");
    //
    //		System.out.println(blockingQueue.remove());
    //		System.out.println(blockingQueue.remove());
    //		System.out.println(blockingQueue.remove());
    //
    //		System.out.println("=======1234========================");
    //
    //		System.out.println(blockingQueue.offer("a"));
    //		System.out.println(blockingQueue.offer("b"));
    //		System.out.println(blockingQueue.offer("c"));
    //		System.out.println(blockingQueue.offer("c"));
    //
    //		String peek = blockingQueue.peek();
    //		System.out.println("peek = " + peek);
    //
    //		System.out.println(blockingQueue.poll());
    //		System.out.println(blockingQueue.poll());
    //		System.out.println(blockingQueue.poll());
    //		System.out.println(blockingQueue.poll());
    //
    //		System.out.println("peek = " + peek);

    System.out.println("=======qwer========================");
    System.out.println("=======qwer========================");
    System.out.println("=======qwer========================");

    try {
      blockingQueue.put("1234");
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
    }
    try {
      blockingQueue.put("1212");
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
    }
    try {
      blockingQueue.put("3434");
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
    }
    try {
      blockingQueue.offer("1111", 4000, TimeUnit.MILLISECONDS);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
    }
    String peek3 = blockingQueue.peek();
    System.out.println("peek1 = " + peek3);

    try {
      blockingQueue.take();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
    }
    try {
      blockingQueue.take();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
    }
    try {
      blockingQueue.take();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
    }
    try {
      blockingQueue.poll(1500, TimeUnit.MILLISECONDS);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
    }

    String peek1 = blockingQueue.peek();
    System.out.println("peek1 = " + peek1);

    System.out.println("main...");
  }
}
